﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        DataSourceSelectArguments sc = new DataSourceSelectArguments();

        String username = tbUsername.Text;
        String pass = tbPass.Text;

        SqlDataSource1.SelectCommand = "select * from Users where username = '" + username + "' and password = '" + pass + "'";
        DataView dv = (DataView)SqlDataSource1.Select(sc);

        if (dv.Count != 0)
        {
            Session["Logined"] = true;
            Session["Userrole"] = dv[0][3].ToString();
            Session["Username"] = dv[0][4].ToString();
            Session["UserID"] = dv[0][0].ToString();
            Response.Redirect("../Default.aspx");
        }
        else
        {
            lbWarning.Text = "Username or Password incorrect";
        }
    }
}